<?php
/**
 * 补发订管理
 */

define('IN_ECS', true);

require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . 'includes/lib_order.php');
require_once(ROOT_PATH . 'includes/lib_goods.php');
@ini_set('display_errors',        2);
$step = !empty($_REQUEST['step'])?$_REQUEST['step']:'add';
/*------------------------------------------------------ */
//-- 补发单列表
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'remedy_list')
{   
    /* 检查权限 */
    admin_priv('back_view');
    $smarty->assign('ur_here',"补发单列表");
    $remedy_list=remedy_list();//获取退货单列表
    $smarty->assign('full_page',       1);
    $smarty->assign('filter',       $remedy_list['filter']);
    $smarty->assign('record_count', $remedy_list['record_count']);
    $smarty->assign('page_count',   $remedy_list['page_count']);
    $smarty->assign('remedy_list',  $remedy_list['remedy_list']);
    $smarty->display('remedy/remedy_list.htm');
}

//分页
elseif ($_REQUEST['act'] == 'remedy_query')
{
    $remedy_list = remedy_list();//订单列表
    $smarty->assign('filter',       $remedy_list['filter']);
    $smarty->assign('record_count', $remedy_list['record_count']);
    $smarty->assign('page_count',   $remedy_list['page_count']);
    $smarty->assign('remedy_list',  $remedy_list['remedy_list']);
    $smarty->assign('languages', $_LANG);   // 快递类型
    make_json_result($smarty->fetch('remedy/remedy_list.htm'), '', array('filter' => $remedy_list['filter'], 'page_count' => $remedy_list['page_count']));

}



/*------------------------------------------------------ */
//-- 查看退货单
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'info')
{   
    $smarty->assign('ur_here',"补发单详情");
    $smarty->assign('action_link', array('href' => 'remedy.php?act=remedy_list', 'text' => '补发单列表'));
    $remedy_id =!empty($_REQUEST['remedy_id'])?$_REQUEST['remedy_id']:'';
    $remedy_info = remedy_info($remedy_id);
    $smarty->assign('remedy_info',$remedy_info);
    $smarty->display('remedy/remedy_info.htm');
}


/*退货单详情*/
function remedy_info($remedy_id){
    $sql = "SELECT * FROM ".$GLOBALS['ecs']->table('order_remedy_info')." WHERE remedy_id = $remedy_id ";
    $remedy_info = $GLOBALS['db']->getRow($sql);
    $remedy_info['add_time'] =date('Y-m-d-H:m:s',$remedy_info['add_time']);
    $sql = "SELECT * FROM ".$GLOBALS['ecs']->table('order_remedy_goods')." WHERE remedy_id = $remedy_id ";
    $remedy_goods = $GLOBALS['db']->getAll($sql);
    $remedy_info['goods_list']=$remedy_goods;
    return $remedy_info;
}






/*退货单列表*/
function remedy_list(){
        $where = 'WHERE 1 ';
        /* 分页大小 */
        $filter['page'] = empty($_REQUEST['page']) || (intval($_REQUEST['page']) <= 0) ? 1 : intval($_REQUEST['page']);
        if (isset($_REQUEST['page_size']) && intval($_REQUEST['page_size']) > 0)
        {
            $filter['page_size'] = intval($_REQUEST['page_size']);
        }
        elseif (isset($_COOKIE['ECSCP']['page_size']) && intval($_COOKIE['ECSCP']['page_size']) > 0)
        {
            $filter['page_size'] = intval($_COOKIE['ECSCP']['page_size']);
        }
        else
        {
            $filter['page_size'] = 15;
        }
        $sql= "SELECT * FROM ".$GLOBALS['ecs']->table('order_remedy_info') .$where."  ORDER BY add_time DESC";
        $filter['record_count'] = $GLOBALS['db']->num_rows($GLOBALS['db']->query($sql)); // 总数
        $filter['page_count']     = $filter['record_count'] > 0 ? ceil($filter['record_count'] / $filter['page_size']) : 1;//总数
        $sql = $sql." LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",$filter[page_size]";
        $row = $GLOBALS['db']->getAll($sql);
        foreach ($row as $key => $value) {
            $row[$key]['add_time'] =date('Y-m-d-H:m:s',$value['add_time']);
        }
        $arr = array('remedy_list' => $row, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
        return $arr;
}



?>